package com.bestv.search.common.model.uid;

public class UID {
    private static long lastTime = System.currentTimeMillis();
    private static short lastCount = 0;
    private static Object mutex = new Object();

    public UID() {
    }

    public static String getUID(Object o) {
        long l = 0L;
        short word0;
        int i;
        synchronized (mutex) {
            if (lastCount == 999) {
                for (boolean flag = false; !flag; ) {
                    l = System.currentTimeMillis();
                    long ONE_SECOND = 1000L;
                    if (l < lastTime + ONE_SECOND) {
                        try {
                            Thread.currentThread();
                            Thread.sleep(ONE_SECOND);
                        } catch (InterruptedException interruptedexception) {
                        }
                    } else {
                        lastTime = l;
                        lastCount = 0;
                        flag = true;
                    }
                }
            } else {
                l = lastTime;
            }
            word0 = lastCount++;
            i = getHostUniqueNum(o);
        }
        String hscode = Integer.toString(i);
        String s = Long.toString(l) + word0 + hscode.substring(hscode.length() - 2);
        if (s.length() > 18)
            s = s.substring(0, 18);
        return s;
    }

    private static int getHostUniqueNum(Object o) {
        return o.hashCode();
    }

}